class Solution:
    def numTrees(self, n: int) -> int:
        if n<=0:
            return 0
        dp = [0] * (n+1)
        dp[0] = 1
        dp[1] = 1
        for end in range(2,n+1):
            for i in range(0,end):
                dp[end] += dp[i] * dp[end-1-i]

        return dp[-1]


if __name__ == '__main__':
    so = Solution()
    n = 3
    r = so.numTrees(n)
    print(r)
